package test0109;

import java.util.ArrayList;
import java.util.List;

public class Test05 {
    public static void main(String[] args) {
        // (5)根据需求写出实现代码

//        // 创建公司
        CC c = new CC("IBM");
//        // 创建员工
        EE e1 = new EE("张三", 30, 3000);
        EE e2 = new EE("李四", 40, 4000);
        EE e3 = new EE("王五", 50, 5000);
//        // 公司添加员工(集合)
        c.add(e1);
        c.add(e2);
        c.add(e3);
        c.add(new EE("赵六", 60, 6000));
        // 打印员工信息
        c.printAll();
//        // 找出年龄最大员工
        EE x = c.m1();

//        // 找出工资最低工资
        EE y = c.m2();
//        // 找出李四员工
        EE z = c.m3("李四");
//        // 求平均工资
        double d = c.m4();
//        // 找工资高于平均工资的员工
        List list = c.m5();
    }
}
class CC {
    String name;
    List<EE> ee = new ArrayList<EE>();

    public CC() {
    }

    public CC(String name) {
        this.name = name;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    @Override
    public String toString() {
        return "CC{" +
                "name='" + name + '\'' +
                '}';
    }

    public void add(EE e) {
        ee.add(e);
    }

    public void printAll() {
        for (EE e : ee) {
            System.out.println(e);
        }
    }

    public EE m1() {
        int max=0;
        for (EE e : ee) {
            if (max<e.age){
                max = e.age;
            }
        }
        for (EE e : ee) {
            if(e.age==max){
                System.out.println(e);
                return e;
            }
        }
        return null;
    }

    public EE m2() {
        int min=ee.get(0).salary;
        for (EE e : ee) {
            if (e.salary<min){
                min=e.salary;
            }
        }
        for (EE e : ee) {
            if(e.salary==min){
                System.out.println(e);
                return e;
            }
        }
        return null;
    }

    public EE m3(String n) {
        for (EE e : ee) {
            if(e.name==n){
                System.out.println(e);
                return e;
            }
        }
        return null;
    }

    public double m4() {
        double sum=0;
        for (EE e : ee) {
            sum+=e.salary;
        }
        System.out.println(sum/ ee.size());
        return sum/ ee.size();
    }

    public List m5() {
        int sum=0;
        for (EE e : ee) {
            sum+=e.salary;
        }
        int n=0;
        for (EE e : ee) {
            if(e.salary>sum/ee.size()){
                n++;
            }
        }
        List<EE> list = new ArrayList(n);
        for (EE e : ee) {
            if(e.salary>sum/ee.size()){
                list.add(e);
            }
        }
        for (EE list1:list){
            System.out.println(list1);
        }
        return list;
    }
}
class EE{
    String name;
    int age;
    int salary;

    public EE() {

    }
    public EE(String name, int age, int salary) {
        this.name = name;
        this.age = age;
        this.salary = salary;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public int getAge() {
        return age;
    }

    public void setAge(int age) {
        this.age = age;
    }

    public int getSalary() {
        return salary;
    }

    public void setSalary(int salary) {
        this.salary = salary;
    }

    @Override
    public String toString() {
        return "EE{" +
                "name='" + name + '\'' +
                ", age=" + age +
                ", salary=" + salary +
                '}';
    }
}
